<template>
  <div
    class="wrap-item"
    :style="{
      '--scroll-width': '80px',
    }"
  >
    <div class="wrap-btn-group">
      <span class="wrap-btn wrap-go-back" @click="go">返回</span>
    </div>
    <div class="wrap-other-roll">
      <!-- 基础信息 -->
      <div class="card">
        <div class="title">基础信息</div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="事件类型">
            {{ info.eventType }}
          </el-descriptions-item>
          <el-descriptions-item label="添加时间">
            {{ info.addTime }}
          </el-descriptions-item>
          <el-descriptions-item label="事件内容" :span="2">
            <json-viewer
              v-if="info.eventContent"
              :value="JSON.parse(info.eventContent)"
              copyable
            ></json-viewer>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div class="card" v-for="(item, index) in list" :key="index">
        <div class="title">
          {{ item.appId }}
          <div class="reset">
            <span
              class="wrap-btn wrap-default"
              @click="reset(item)"
              v-if="$checkPermission(107)"
              >重置</span
            >
          </div>
        </div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="通知时间" :span="2">
            {{ item.notifyTime }}
          </el-descriptions-item>
          <el-descriptions-item label="处理次数">
            {{ item.notifyCount }}
          </el-descriptions-item>
          <el-descriptions-item label="状态">
            <span v-if="item.notifyStatus == 0">待处理</span>
            <span v-if="item.notifyStatus == 1">处理中</span>
            <span v-if="item.notifyStatus == 2">失败</span>
            <span v-if="item.notifyStatus == 3">成功</span>
          </el-descriptions-item>
          <el-descriptions-item label="通知地址" :span="2">
            {{ item.notifyUrl }}
          </el-descriptions-item>
          <el-descriptions-item label="通知结果" :span="2">
            <json-viewer
              v-if="item.notifyResult"
              :value="JSON.parse(item.notifyResult)"
              copyable
            ></json-viewer>
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </div>
  </div>
</template>

<script>
import JsonViewer from 'vue-json-viewer'
export default {
  components: { JsonViewer },
  data() {
    return {
      info: {},
      list: [],
    }
  },
  created() {
    this.itemList()
  },
  methods: {
    go() {
      //返回
      this.$store.dispatch('tags/delVisitedRoute', {
        path: this.$route.path,
      })
      this.$router.push('/applicationCenter/subscribe')
    },
    itemList() {
      // 获取列表
      this.$axios
        .get('/admin/appevent/findById?id=' + this.$route.query.id)
        .then((data) => {
          this.info = {}
          this.list = []
          if (data.code == 200) {
            this.info = data.data.info
            this.list = data.data.apps
          } else {
            this.$message.error(data.msg)
          }
        })
    },
    reset(row) {
      this.$confirm('您确定要重置该条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$axios
            .get('/admin/appevent/resetStatus?id=' + row.id)
            .then((data) => {
              if (data.code == 200) {
                this.itemList()
                this.$message.success('操作成功！')
              } else {
                this.$message.error(data.msg)
              }
            })
        })
        .catch(() => {})
    },
  },
}
</script>
<style lang="scss" scoped>
.card {
  padding-bottom: 20px;
  .title {
    color: #45ab49;
    border-bottom: 1px solid #45ab49;
    padding: 10px 0;
    margin-bottom: 15px;
    .reset {
      float: right;
      margin-top: -15px;
    }
  }
}
</style>
